import {
  CarryOutOutlined,
  DeleteOutlined,
  FormOutlined,
  PlusCircleOutlined,
} from "@ant-design/icons";
import { Tree } from "antd";
import React, { useState } from "react";

const Data = [
  {
    title: "苏州安装集团有限公司",
    key: "1",
    // icon: <PlusCircleOutlined />,
    children: [
      {
        title: "人事行政部",
        key: "11",
        // icon: <PlusCircleOutlined />,
        children: [
          {
            title: "人事部",
            key: "111",
            // icon: <PlusCircleOutlined />,
            children: [
              {
                title: "培训科",
                key: "1111",
                // icon: <PlusCircleOutlined />,
              },
            ],
          },
          {
            title: "行政部",
            key: "112",
            // icon: <PlusCircleOutlined />,
          },
        ],
      },
      {
        title: "安防管理中心",
        key: "12",
        // icon: <CarryOutOutlined />,
        children: [
          {
            title: "leaf",
            key: "113",
            // icon: <CarryOutOutlined />,
          },
        ],
      },
      {
        title: "环保管理中心",
        key: "13",
        // icon: <PlusCircleOutlined />,
        children: [
          {
            title: "leaf",
            key: "114",
            // icon: <PlusCircleOutlined />,
          },
          {
            title: "leaf",
            key: "115",
            // icon: <PlusCircleOutlined />,
            // switcherIcon: <FormOutlined />,
          },
        ],
      },
    ],
  },
];
export default function Bumenguanli() {
  const [showLine] = useState(false);
  const [showIcon] = useState(true);
  // const [showLeafIcon] = useState(true);
  sessionStorage.setItem("data", JSON.stringify(Data));
  const treeData = bindData(
    sessionStorage.getItem("data")
      ? JSON.parse(sessionStorage.getItem("data"))
      : []
  );
  function bindData(data) {
    let arr = [];
    arr = data.map((item) => {
      if (item.children && item.children.length > 0) {
        return {
          title: item.title,
          key: item.key,
          // icon: item.icon,
          children: [...bindData(item.children)],
        };
      } else {
        return {
          title: item.title,
          key: item.key,
          // icon:item.icon
        };
      }
    });
    return arr;
  }
  return (
    <div>
      <Tree
        showLine={showLine}
        showIcon={showIcon}
        defaultExpandedKeys={[1]}
        treeData={treeData}
      />
      <div>
        <PlusCircleOutlined />
        <FormOutlined />
        <DeleteOutlined />
      </div>
    </div>
  );
}
